import React from 'react';
import './App.css';
import {FC} from 'react';
import {Button} from 'antd'
// 引入主组件的页面布局
import Index from  './layout/index'
import { Navigate, Route, Routes, useLocation } from 'react-router-dom';
// 导入登录页
import {Index as Login}  from './views/login/Index'
// 获取redux中的登录状态
import { useAppSelector } from './store/hooks';

type AppProps = {}
const App = (props:AppProps)=>{
  // 拿到的登录状态，导航守卫在react中不需要 直接在对应的地方写逻辑即可
  const loginState = useAppSelector(state=>state.user.loginState)
  // 登录添加
  const {search} =useLocation()
  const redirectUrl = search.split('?r=')[1]
  const str =redirectUrl ? redirectUrl : '/'
  return (
    <Routes>
      {/* <Route path="/login" element = { <Login /> } />
       */}
       <Route path="/login" element = { loginState ? < Navigate to={str}/> : <Login /> } />
      <Route path="/*" element={loginState ? <Index /> : <Navigate to="/login" />} />
    </Routes>
  );
}

export default App;
